<?php
/**
 * This file defines the static class '\BF\RX'.
 *
 * @author     Kado <ulfikado@gmail.com>
 * @category   Beluga PHP5.3+ Framework
 * @package    BF\Core
 * @since      2015-01-17 14:29
 * @subpackage Helpers
 * @version    0.1
 */

namespace BF
{

   /**
    * A static class for defining some regular expressions.
    *
    * @since  v0.1
    */
   class RX
   {

      # <editor-fold defaultstate="collapsed" desc=" - - -   C O N S T A N T S   - - - - - - - - - - - - - - - - - - - - - - - - - - -">

      /**
       * This regular expression matches if the testing string exclusively contains characters
       * from hexadecimal range (a-fA-F0-9).
       */
      const HEX_RANGE = '~^[a-fA-F0-9]+$~';

      /**
       * This regular expression matches if the testing string exclusively contains character pairs (always 2)
       * from hexadecimal range (a-fA-F0-9).
       */
      const HEX_VALUE = '~^([a-fA-F0-9]{2})+$~';

      /**
       * This regular expression matches if the testing string uses a valid email address format.
       * Matching group 1 point to the used host/domain.
       */
      const EMAIL = '~^[A-Za-z_][A-Za-z0-9_.-]*@([A-Za-z][A-Za-z0-9_.-]+)$~';

      /**
       * This regular expression matches if the testing string contains same bad or immoral words.
       */
      const BADWORDS = '~\b(dumm|fick|arsch|nazi|hoden|votze|fotze|viagra|anal|dollar|valium|sex|pussy|hitler|fuck|casino|money|penis|cash|money|pharma|rabat|health|mall|adult|dollar|buss?ines|\$\d+|gina|winner|sweepstakes|lottery|payment|medicine|hospital|jewel|shopping|jude|himmler|bonus|islam)~i';

      /**
       * This regular expression matches if the testing string contains some text, written with some unusable spacings
       * to hide Spamword from filters (e.g.: 'V i a  g r a'   or   'V--A--L--i--u--M')
       */
      const INCONSISTENT_TEXT = '~[\pL\pN]([ \t#+,;-]+[\pL\pN]){4,}~';

      /**
       * This regular expression matches if the testing string can be used as password without special chars.
       */
      const PASSWORD = '~^[a-zA-Z_.-]{6,24}$~';

      /**
       * Finds all URLs iside a string to check. It returns the following match groups: 1=protocol, 2=host, 3=path+
       */
      const URL_FIND = '~(https?|ftp)://([a-z0-9_.-]+)(/[a-z0-9_./+%?&#]+)?~i';

      /**
       * This regular expression matches if the testing string contains some URL encoded elements.
       */
      const URL_ENCODING = '~%[\dA-Fa-f]{2}~';

      /**
       * This regular expression matches if the testing string contains some HTML entities.
       */
      const HTML_ENTITY = '~&([A-Za-z]{2,7}|#[\dA-Fa-f]{2,4});~';

      /**
       * This regular expression matches if the testing string uses a valid phone numer format, containg the country
       * code (matching group 1) the city code (matching group 3) and the regional number it self (matching group 4)
       */
      const PHONE_NUMBER_FULL = '~^((\+|00)\d{2,4})[ -/]([1-9]\d{2,6})[ -/]([1-9]\d{2,7}([ -/]\d{1,4})?)$~';

      /**
       * This regular expression matches if the testing string uses a valid phone numer format, containg the
       * city code (matching group 1) and the regional number it self (matching group 3)
       */
      const PHONE_NUMBER = '~^(0([1-9]\d{1,6}))[ -/]([1-9]\d{2,7}([ -/]\d{1,4})?)$~';

      /**
       * This regular expression matches, if the tested string represents a valid PHP word, usable as function name,
       * class name, etc. There is a min. length of 1 and a max. length of 255 characters.
       */
      const PHP_WORD = '~^[A-Za-z_][A-Za-z0-9_]{0,254}$~';

      # </editor-fold>

      # <editor-fold defaultstate="collapsed" desc=" - - >   P R I V A T E   C O N S T R U C T O R   - - - - - - - - - - - - - - - - -">

      /**
       * Inits a new instance.
       */
      private function __construct() { }

      # </editor-fold>

      /**
       * Tests if $str is a usable PHP word. Itz means if $str is usable as function-, method-, class- or variable name
       * etc.
       *
       * @param  string $str The string to test
       * @return boolean
       */
      public static function IsPhpWord( $str )
      {

         return (bool) \preg_match( self::PHP_WORD, $str );

      }

   }

}

